package com.example.user.controller;

import com.example.common.result.Result;
import com.example.user.api.LoginDTO;
import com.example.user.api.LoginResponseDTO;
import com.example.user.service.AuthService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result<LoginResponseDTO> login(@Valid @RequestBody LoginDTO loginDTO) {
        LoginResponseDTO response = authService.login(loginDTO);
        return Result.success(response);
    }

    @PostMapping("/logout")
    @ApiOperation("用户登出")
    public Result<Boolean> logout(@RequestBody String token) {
        authService.logout(token);
        return Result.success(true);
    }
}
